
public class CpuIntensiveTask implements Runnable {
    private volatile boolean running;

    public CpuIntensiveTask(boolean running) {
        this.running = running;
    }

    public void stop() {
        this.running = false;
    }

    @Override
    public void run() {
        long counter = 0;
        while (running) {
            // 简单的计算任务，保持CPU忙碌
            counter = (counter + 1) % Long.MAX_VALUE;
            if (counter % 1000000000 == 0) {
                Thread.yield();
            }
        }
        System.out.println(Thread.currentThread().getName() + " 已停止");
    }
}